package com.zhang.servlet;

import com.zhang.pojo.ManBean;
import com.zhang.service.IManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.print.DocPrintJob;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Controller
public class AddServlet extends HttpServlet {
    @Autowired
    private IManService manService;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");
        resp.setContentType("text/html;charset=utf-8");
        String username = req.getParameter("username");
        String birthday = req.getParameter("birthday");
        manService.add(new ManBean(username,birthday));
        resp.sendRedirect("/findAll");
    }
}
